{extend name="common/base"}
{block name="extend_css"}
<link rel="stylesheet" type="text/css" href="/bower/bootstrap-table/dist/bootstrap-table.css">
{/block}
{block name="content"}
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>{$title|default='后台管理'}</legend>
</fieldset>
<div style="margin-left: 20px;">
    <div class="layui-btn-group">
        <button class="layui-btn" onclick=edit("{:url('admin/database/backup')}");>立即备份</button>
        <button class="layui-btn" onclick=edit("{:url('admin/database/optimize')}");>优化表</button>
        <a class="layui-btn" onclick=edit("{:url('admin/database/repaire')}");>修复表</a>
    </div>
    <div></div>
    <table id="bt" data-toggle="table"  data-sort-name="xh" data-sort-order="asc"  data-pagination="true" id="bt" data-page-size="5"
           data-search="true" data-show-refresh="true" data-show-toggle="true" data-show-columns="true" data-page-list="[3,10,20,'all']">
        <thead>
        <tr>
            <th data-checkbox="true"></th>
            <th data-field="Name" data-sortable="true">表名</th>
            <th data-field="Rows">数据量</th>
            <th data-field="Data_length" data-sortable="true">数据大小</th>
            <th data-field="create_time" data-sortable="true">创建时间</th>
            <th data-field="back" data-sortable="true">备份状态</th>
            <th data-field="action">操作</th>
        </tr>
        </thead>
        <tbody>
        {notempty name="data"}
        {foreach $data as $vo}
        <tr>
            <td></td>
            <td>{$vo.Name}</td>
            <td>{$vo.Rows}</td>
            <td>{$vo.Data_length}</td>
            <td>{$vo.Create_time}</td>
            <td id="{$vo.Name}">未备份</td>
            <td>
                <div class="layui-btn-group">
                    <a class="layui-btn layui-btn-normal layui-btn-sm" href="{:url('admin/database/optimize',['ids'=>$vo.Name])}">优化表</a>
                    <a class="layui-btn layui-btn-danger layui-btn-sm" href="{:url('admin/database/repaire',['ids'=>$vo.Name])}">修复表</a>
                </div>
            </td>
        </tr>
        {/foreach}
        {/notempty}
        </tbody>
    </table>
</div>
{/block}
{block name="extend_js"}
<script src="/bower/bootstrap-table/dist/bootstrap-table.js"></script>
<script src="/bower/bootstrap-table/dist/locale/bootstrap-table-zh-CN.js"></script>
<script src="/plugin/tableExport/tableExport.js"></script>
<script src="/bower/bootstrap-table/dist/extensions/export/bootstrap-table-export.js"></script>
<script src="/global/list.js"></script>
<script>
    $('#bt').bootstrapTable({showExport:true,exportDataType:"all"});
    /*获取bootstrap table 的复选框值*/
    function selectM(){
        //bootstrap获取所有被选择的表格的方法
        var rows = $("#bt").bootstrapTable('getSelections');
        if (rows.length== 0) {
            alert("请先选择要删除的记录!");
            return;
        }
        var ids = '';
        for (var i = 0; i < rows.length; i++) {
            ids += rows[i]['Name'] + ",";
        }
        ids = ids.substring(0, ids.length - 1);
        // layer.alert(ids);
        return ids;
    }

    /**
     * ajax数据提交相关数据,根据url来控制
     * @param url
     */
    function edit(url){
        var select=selectM();
        var ns=select.replace(/think/g,'#think');
        $.ajax({
            url:url,
            type:'POST',
            dataType:'json',
            data:{'ids':select}
        })
        .done(function (data){
//            console.log(data);
            if(data.code==1){
                $(ns).html('已备份');
                layer.alert(data.msg);
            }else{
                layer.alert(data.msg);
            }
        })
        .fail(function() {
            layer.alert("error");
        });
    }
</script>
{/block}